﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace IT_Pro.Class
{
    class CV_GhiNhanYCSuaChua
    {
        private DateTime _ngYC;

        public DateTime NgYC
        {
            get { return _ngYC; }
            set { _ngYC = value; }
        }
        private string _nguoiYC;

        public string NguoiYC
        {
            get { return _nguoiYC; }
            set { _nguoiYC = value; }
        }
        private int _loaiYC;

        public int LoaiYC
        {
            get { return _loaiYC; }
            set { _loaiYC = value; }
        }
        private string _noiDung;

        public string NoiDung
        {
            get { return _noiDung; }
            set { _noiDung = value; }
        }
        private string _mamay;

        public string Mamay
        {
            get { return _mamay; }
            set { _mamay = value; }
        }

        private DateTime _tuNgay;

        public DateTime TuNgay
        {
            get { return _tuNgay; }
            set { _tuNgay = value; }
        }
        private DateTime _denNgay;

        public DateTime DenNgay
        {
            get { return _denNgay; }
            set { _denNgay = value; }
        }
        private int _xuLy;

        public int XuLy
        {
            get { return _xuLy; }
            set { _xuLy = value; }
        }

        private int _loi;

        public int Loi
        {
            get { return _loi; }
            set { _loi = value; }
        }

        private int _id;

        public int Id
        {
            get { return _id; }
            set { _id = value; }
        }

        private string _nguoiTH;

        public string NguoiTH
        {
            get { return _nguoiTH; }
            set { _nguoiTH = value; }
        }

        private string _nguyenNhan;

        public string NguyenNhan
        {
            get { return _nguyenNhan; }
            set { _nguyenNhan = value; }
        }
        private string _khacPhuc;

        public string KhacPhuc
        {
            get { return _khacPhuc; }
            set { _khacPhuc = value; }
        }
        private string _ghiChu;

        public string GhiChu
        {
            get { return _ghiChu; }
            set { _ghiChu = value; }
        }
        private DateTime _ngayHT;

        public DateTime NgayHT
        {
            get { return _ngayHT; }
            set { _ngayHT = value; }
        }

        public static DataTable LoadLoaiYeuCauSuaChua()
        {
            string procName = "cv_LoaiYeuCauSuaChua";
            return DataServices.ExcuteProcedureGetTable(procName, null);
        }

        public int LapPhieuYCSuaChua()
        {
            string procName = "cv_LapPhieuYeuCauSuaChua";
            SqlParameter[] parameters = new SqlParameter[6];
            parameters[0] = new SqlParameter("@ngayyc", NgYC);
            parameters[1] = new SqlParameter("@nguoiyc", NguoiYC);
            parameters[2] = new SqlParameter("@loaiyc", LoaiYC);
            parameters[3] = new SqlParameter("@noidung", NoiDung);
            parameters[4] = new SqlParameter("@mamay", Mamay);
            parameters[5] = new SqlParameter("@maytinh", "");
            int i = DataServices.ExcuteProcedureWithReturn(procName, parameters);
            return i;
        }

        public DataTable LoadDsYeuCauSuaChua()
        {
            string procName = "cv_HienThiDanhSachYCSuaChua";
            SqlParameter[] parameters = new SqlParameter[3];
            parameters[0] = new SqlParameter("@suly", XuLy);
            parameters[1] = new SqlParameter("@ngbd", TuNgay);
            parameters[2] = new SqlParameter("@ngaykt ", DenNgay);
            return DataServices.ExcuteProcedureGetTable(procName, parameters);
        }

        public DataTable LoadDsLoi()
        {
            string procName = "cv_HienThiDanhSachLoi";
            SqlParameter[] parameters = new SqlParameter[1];
            parameters[0] = new SqlParameter("@loi", Loi);         
            return DataServices.ExcuteProcedureGetTable(procName, parameters);
        }

        public int XacNhanDangXuLyYC()
        {
            string procName = "cv_CapNhatTinhTrangYCSC";
            SqlParameter[] parameters = new SqlParameter[3];
            parameters[0] = new SqlParameter("@id", Id);
            parameters[1] = new SqlParameter("@nguoith", NguoiTH);
            parameters[2] = new SqlParameter("@ngayth", DateTime.Now);          
            int i = DataServices.ExcuteProcedureWithReturn(procName, parameters);
            return i;
        }

        public int CapNhatXuLyYC()
        {
            string procName = "cv_CapNhatXuLyYeuCauSC";
            SqlParameter[] parameters = new SqlParameter[7];
            parameters[0] = new SqlParameter("@id", Id);
            parameters[1] = new SqlParameter("@xuly", XuLy);
            parameters[2] = new SqlParameter("@nguoith", NguoiTH);
            parameters[3] = new SqlParameter("@nguyennhan",NguyenNhan);
            parameters[4] = new SqlParameter("@khacphuc",KhacPhuc);
            parameters[5] = new SqlParameter("@ghichu", GhiChu);
            parameters[6] = new SqlParameter("@ngayht", NgayHT);
           
            int i = DataServices.ExcuteProcedureWithReturn(procName, parameters);
            return i;
        }

        public static string[] KiemTraYCSCMoi()
        {
            string procName = "kt_KiemTraPhieuYCSCMoi";           
            DataTable dt = DataServices.ExcuteProcedureGetTable(procName, null);
            if (dt.Rows.Count > 0)
            {
                string[] strThongBao = new string[dt.Rows.Count];
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    strThongBao[i] = " *-* Yêu cầu Sửa chữa mới số: " + dt.Rows[i]["ID"].ToString() + "\r\n Lỗi: " + dt.Rows[i]["TenLoaiSC"].ToString() + " \r\n Yêu cầu: " + dt.Rows[i]["NoiDung"].ToString() + " \r\n";
                }
                return strThongBao;
            }
            else
            {
                return null;
            }
        }

        public int HuyPhieuYC()
        {
            string procName = "cv_HuyPhieuYeuCauSC";
            SqlParameter[] parameters = new SqlParameter[1];
            parameters[0] = new SqlParameter("@id", Id);           
            int i = DataServices.ExcuteProcedureWithReturn(procName, parameters);
            return i;
        }


         public int DoiThongTinMay()
        {
            string procName = "cv_DoiThongTinMayTinh";
            SqlParameter[] parameters = new SqlParameter[2];
            parameters[0] = new SqlParameter("@id", Id);
            parameters[1] = new SqlParameter("@mamay",Mamay );
           
            int i = DataServices.ExcuteProcedureWithReturn(procName, parameters);
            return i;
        }
    }
}
